// internal/planner/optimizer/optimizer.go
package optimizer

import (
    "NumberBase/internal/planner/types"
)

// Rule 表示优化规则接口
type Rule interface {
    // 应用规则到计划上
    Apply(plan types.LogicalPlan) types.LogicalPlan
}

// Optimizer 包含一组优化规则
type Optimizer struct {
    rules []Rule
}

// New 创建新的优化器
func New() *Optimizer {
    opt := &Optimizer{}
    
    // 注册优化规则
    opt.rules = []Rule{
        &PredicatePushDown{},
        &ProjectionPruning{},
        // 更多规则...
    }
    
    return opt
}

// Optimize 应用所有规则优化计划
func (o *Optimizer) Optimize(plan types.LogicalPlan) types.LogicalPlan {
    result := plan
    
    // 应用每一条规则
    for _, rule := range o.rules {
        result = rule.Apply(result)
    }
    
    return result
}